package com.candy.control;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//处理中文乱码问题
//        req.setCharacterEncoding("UTF-8");
//        resp.setCharacterEncoding("UTF-8");
        //     获取前端用户输入进来的信息
        String username=req.getParameter("username");
        String userpwd=req.getParameter("userpwd");
//       向session中存储用户登录信息
        req.getSession().setAttribute("username",username);
//        页面跳转
        req.getRequestDispatcher("welcome.jsp").forward(req,resp);

    }
}
